﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.Entity;

using WHC.Hotel.BLL;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.UI
{
    public partial class FrmEditRoomGroupOrder : BaseForm
    {
        public RoomInfo RoomInfo = null;
        private Hashtable htBookInfo = new Hashtable();
        private List<OrderInfo> roomlist = new List<OrderInfo>();
        public BookInfo bookInfo = null;
        private string selectedRoomNo = "";
        private string billNumber = string.Empty;
        private List<BookInfo> booklist = null;

        public FrmEditRoomGroupOrder()
        {
            InitializeComponent();
            InitDictItems();
            InitUnitList();
        }

        private void InitDictItems()
        {
            this.txtPayType.Items.Clear();
            this.txtPayType.Items.AddRange(DictItemUtil.GetPayType());
            if (this.txtPayType.Items.Count > 0)
            {
                this.txtPayType.SelectedIndex = 0;
            }

            this.txtCustomerType.Items.Clear();
            this.txtCustomerType.Items.AddRange(DictItemUtil.GetCustomerType());
            if (this.txtCustomerType.Items.Count > 0)
            {
                this.txtCustomerType.SelectedIndex = 0;
            }

            //this.txtCardType.Items.Clear();
            //this.txtCardType.Items.AddRange(DictItemUtil.GetIDCarType());
            //if (this.txtCardType.Items.Count > 0)
            //{
            //    this.txtCardType.SelectedIndex = 0;
            //}

            this.txtSource.Items.Clear();
            this.txtSource.Items.AddRange(DictItemUtil.GetCustomerSource());
            this.txtSource.Items.Insert(0, "未知");
            if (this.txtSource.Items.Count > 0)
            {
                this.txtSource.SelectedIndex = 0;
            }
        }

        private void FrmEditRoomGroupOrder_Load(object sender, EventArgs e)
        {

          
            txtPreOff.Text = Convert.ToDateTime(txtPreArrive.Text).AddDays(1).ToString("yyyy-MM-dd") + " 14:00";
            if (bookInfo != null)
            {

                billNumber = Public.GetOrderNumber();
                txtOrderNo.Text = billNumber;
                //RoomInfo info = BLLFactory<Room>.Instance.FindByRoomNo(BookInfo.RoomNo);

                this.txtCompany.Text = bookInfo.CustomerCompany;
                this.txtName.Text = bookInfo.CustomerName;
                this.txtRemark.Text = bookInfo.Note;
                this.txtNote.Text = bookInfo.Note;
                this.txtPreArrive.Value = DateTime.Now;
                this.txtPreOff.Text = bookInfo.PreOffTime.ToString("yyyy-MM-dd") + " " + "14:00";
                this.txtBookArriveDate.Value = bookInfo.PreArrivalTime;
                this.txtBookOffDate.Value = bookInfo.PreOffTime;
                this.txtTeamName.Text = bookInfo.CustomerName;
                this.txtOrderNo.Text = Public.GetOrderNumber();
                this.txtBookPeople.Text = bookInfo.BookPeople;
                this.txtBookPeoplePhone.Text = bookInfo.BookPeoplePhone;
                this.txtCustomerType.Text = "团体客户";
                TimeSpan span = txtPreOff.Value.Subtract(txtPreArrive.Value.Date);
                txtPrLivedDays.Text = span.Days.ToString();
                booklist = BLLFactory<Book>.Instance.FindTeamBookList(bookInfo.BookNo);
                foreach (BookInfo item in booklist)
                {


                    htBookInfo.Add(item.RoomType, item.RoomCount.ToString());



                }

                this.dgRoom.AutoGenerateColumns = false;
                this.dgRoom.DataSource = new BindingList<OrderInfo>(new List<OrderInfo>());
                ShowBookRoomTypeListView();
                InitAvailableRooms();
                BindSelectedRoomInfo();
            }
            else
            {
                InitAvailableRooms();
                billNumber = Public.GetOrderNumber();
                txtOrderNo.Text = billNumber;
            
            
            }
        }

        /// <summary>
        /// 显示预定房类信息
        /// </summary>
        private void ShowBookRoomTypeListView()
        {

            int serialNum = 1;
            this.lvwBookRooms.Items.Clear();
            foreach (string item in this.htBookInfo.Keys)
            {

                ListViewItem listitem = new ListViewItem(serialNum.ToString());
                listitem.SubItems.Add(item);
                listitem.SubItems.Add(htBookInfo[item].ToString());
                this.lvwBookRooms.Items.Add(listitem);

                serialNum++;
            }


        }
        /// <summary>
        /// 根据用户的房间，获取可供的房间列表
        /// </summary>
        private void InitAvailableRooms()
        {
            #region 项目类型信息明细类别

            this.treeView1.Nodes.Clear();
            this.treeView1.BeginUpdate();

            
            List<RoomTypeInfo> typeList = BLLFactory<RoomType>.Instance.GetAll();
            foreach (RoomTypeInfo typeInfo in typeList)
            {
                string nodeName = string.Format("{0}  {1}", typeInfo.Name, typeInfo.DayPrice.ToString("C2"));
                TreeNode typeNode = new TreeNode(nodeName, 0, 0);
                this.treeView1.Nodes.Add(typeNode);
                //typeNode.Tag = info;
                List<RoomInfo> roomCanUseList= roomCanUseList= BLLFactory<Room>.Instance.FindRoomsByCondition("  RoomType='" + typeInfo.Name + "'  and   (Status='" + RoomStatus.空净房.ToString() + "'  or  Status='" + RoomStatus.空脏房.ToString() + "') ");
               // List<RoomInfo> roomCanUseList = BLLFactory<Room>.Instance.FindRooms(typeInfo.Name, RoomStatus.空净房.ToString());
                foreach (RoomInfo roomInfo in roomCanUseList)
                {
                   
                        TreeNode subNode = new TreeNode(roomInfo.RoomNo, 1, 1);
                        subNode.Tag = roomInfo;
                        typeNode.Nodes.Add(subNode);
                  
                }
            }
            this.treeView1.EndUpdate();
            //this.treeView1.ExpandAll();

            #endregion
        }

        private void InitUnitList()
        {
            List<ProtocolUnitInfo> list = BLLFactory<ProtocolUnit>.Instance.GetAll();
            this.cmbUnit.Items.Clear();
            this.cmbUnit.Items.Add(new CListItem("请选择协议单位", "请选择协议单位"));
            foreach (ProtocolUnitInfo entity in list)
            {
                CListItem item = new CListItem(entity.UnitName, entity.UnitName);
                this.cmbUnit.Items.Add(item);

            }
            this.cmbUnit.SelectedIndex = 0;

        }

        private void BindSelectedRoomInfo()
        {
            
           // this.dgRoom.Columns["Id"].DataPropertyName = "Id";
            this.dgRoom.Columns["RoomNo"].DataPropertyName = "RoomNo";
            this.dgRoom.Columns["RoomType"].DataPropertyName = "RoomType";
            this.dgRoom.Columns["RoomPrice"].DataPropertyName = "OriginalPrice";
            this.dgRoom.Columns["RoomDiscountPrice"].DataPropertyName = "DiscountPrice";
            this.dgRoom.DataSource = new BindingList<OrderInfo>(roomlist);

         
            
     
        
        }



        private void RefreshAddedItems()
        {
           //// this.lsvAdded.Items.Clear();
           // int i = 0;
           // foreach (string roomNo in addedRooms.Keys)
           // {
           //     ListViewItem lvItem = new ListViewItem((i + 1).ToString());
           //     lvItem.SubItems.Add(roomNo);

           //     RoomTypeInfo typeInfo = BLLFactory<RoomType>.Instance.FindByName(addedRooms[roomNo].RoomType);
           //     lvItem.SubItems.Add(typeInfo.Name);
           //     lvItem.SubItems.Add(typeInfo.DayPrice.ToString("f2"));

           //     decimal rate = 1.0M;
           //     RoomDiscountInfo discountInfo = null;
           //     //if (this.txtCustomerType.Text == "协议客户")
           //     //{


           //     //    DiscountInfoInfo mDiscountInfoInfo = BLLFactory<DiscountInfo>.Instance.FindSingle("  UnitName='" + cmbUnit.Text + "' and  RoomType ='" + typeInfo.Name + "'");
           //     //    if (mDiscountInfoInfo != null)
           //     //    {

           //     //        rate = mDiscountInfoInfo.DiscountPercent;
           //     //        lvItem.SubItems.Add(rate.ToString("f2"));
           //     //        lvItem.SubItems.Add(mDiscountInfoInfo.RoomDiscountPrice.ToString("f2"));
           //     //        lvItem.Tag = addedRooms[roomNo];
           //     //    }
           //     //}
           //     //else
           //     //{

                    
           //     //    discountInfo = BLLFactory<RoomType>.Instance.GetDiscountInfo(typeInfo.Name, this.txtCustomerType.Text);
           //     //    if (discountInfo != null)
           //     //    {
           //     //        rate = Convert.ToDecimal(discountInfo.DiscountRate);
           //     //    }
           //     //    lvItem.SubItems.Add(rate.ToString("f2"));
           //     //    lvItem.SubItems.Add((typeInfo.DayPrice * rate).ToString("f2"));
           //     //    lvItem.Tag = addedRooms[roomNo];

           //     //}

           //     if (this.txtCustomerType.Text != "协议客户")
           //     {

           //         if (cmbUnit.Text != "请选择协议单位")
           //         {
           //             DiscountInfoInfo mDiscountInfoInfo = BLLFactory<DiscountInfo>.Instance.FindSingle("  UnitName='" + cmbUnit.Text + "' and  RoomType ='" + typeInfo.Name + "'");
           //             if (mDiscountInfoInfo != null)
           //             {

           //                 rate = mDiscountInfoInfo.DiscountPercent;
           //                 lvItem.SubItems.Add(rate.ToString("f2"));
           //                 lvItem.SubItems.Add(mDiscountInfoInfo.RoomDiscountPrice.ToString("f2"));
           //                 lvItem.Tag = addedRooms[roomNo];
           //             }

           //         }
           //         else
           //         {

           //             discountInfo = BLLFactory<RoomType>.Instance.GetDiscountInfo(typeInfo.Name, this.txtCustomerType.Text);
           //             if (discountInfo != null)
           //             {
           //                 rate = Convert.ToDecimal(discountInfo.DiscountRate);
           //             }
           //             lvItem.SubItems.Add(rate.ToString("f2"));
           //             lvItem.SubItems.Add((typeInfo.DayPrice * rate).ToString("f2"));
           //             lvItem.Tag = addedRooms[roomNo];

           //         }


           //     }
           //     else//按协议单位处理
           //     {

           //         DiscountInfoInfo mDiscountInfoInfo = BLLFactory<DiscountInfo>.Instance.FindSingle("  UnitName='" + cmbUnit.Text + "' and  RoomType ='" + typeInfo.Name + "'");
           //         if (mDiscountInfoInfo != null)
           //         {

           //             rate = mDiscountInfoInfo.DiscountPercent;
           //             lvItem.SubItems.Add(rate.ToString("f2"));
           //             lvItem.SubItems.Add(mDiscountInfoInfo.RoomDiscountPrice.ToString("f2"));
           //             lvItem.Tag = addedRooms[roomNo];
           //         }


           //     }

           //    // this.lsvAdded.Items.Add(lvItem);
           //     i++;
           // }
        }
        
        private void txtCustomerType_SelectedIndexChanged(object sender, EventArgs e)
        {
           // RefreshAddedItems();
        }


        private void ChangeCustomer(string customerID)
        {
            if (!string.IsNullOrEmpty(customerID))
            {
                CustomerInfo info = BLLFactory<Customer>.Instance.FindByID(customerID);
                if (info != null)
                {
                    //this.txtAddress.Text = info.Address;
                    //this.txtCardType.Text = info.IDCarType;
                    //this.txtCompanyName.Text = info.CompanyName;

                    int i = txtCustomerType.FindStringExact(info.CustomerType);
                    this.txtCustomerType.SelectedIndex = i;

                    //this.txtIDNumber.Text = info.IDNumber;
                    //this.txtName.Text = info.Name;
                    //this.txtSex.Text = info.Sex;
                    //this.txtTelephone.Text = info.Telephone;
                    //this.txtSource.Text = info.Source;
                    //this.txtNote.Text = info.Note;
                }
            }
        }



  

        private void btnOK_Click(object sender, EventArgs e)
        {
           

           

            if (txtTeamName.Text == "")
            {

                MessageUtil.ShowTips("团队名称不能为空");
                this.txtTeamName.Focus();
                return;
            
            }

            if (roomlist.Count < 1)
            {


                MessageUtil.ShowTips("请先为团队选择房间");
                return;
            
            }

            if (txtPayType.Text == "现金")
            {

                if (Convert.ToDecimal(txtDeposit.Text) < 1)
                {

                    MessageUtil.ShowTips("请输入实收押金金额");
                    this.txtDeposit.Focus();
                    return;

                }
            }

            //构造虚拟账户
            OrderInfo virtualAccount = new OrderInfo();

            if (bookInfo != null)
            {
                billNumber = bookInfo.BookNo;
                virtualAccount.BillNumber = bookInfo.BookNo;
                virtualAccount.OrderNo =txtOrderNo.Text;
                virtualAccount.RoomNo = bookInfo.BookNo + "-V8888";
                virtualAccount.MasterRoomNo = bookInfo.BookNo + "-V8888";
            }
            else
            {

                virtualAccount.BillNumber = billNumber;
                virtualAccount.OrderNo = txtOrderNo.Text;
                virtualAccount.RoomNo = billNumber + "-V8888";
                virtualAccount.MasterRoomNo = billNumber + "-V8888";
            
            }
            virtualAccount.CheckType = 1;
            virtualAccount.CreateDate = Convert.ToDateTime(txtPreArrive.Text);
            virtualAccount.PreOffDate = Convert.ToDateTime(txtPreOff.Text);
            virtualAccount.Createor = Portal.gc.LoginInfo.FullName;
            virtualAccount.Persons = Convert.ToInt32(txtPersons.Text);
            virtualAccount.PreLivedDays = Convert.ToInt32(txtPrLivedDays.Text);
            virtualAccount.PreGrantNum = txtPreGrantNum.Text;
            virtualAccount.PayType = txtPayType.Text;      
            virtualAccount.ProtocolUnit = cmbUnit.Text;
            virtualAccount.TeamName = txtTeamName.Text;
            virtualAccount.Note = txtNote.Text;
            virtualAccount.IsVirtualAccount = 1;
            virtualAccount.IsSecret = false;
            virtualAccount.IsPartTime = false;
            virtualAccount.IsEachPay = false;
            virtualAccount.CreditCardMax = Convert.ToDecimal(txtCreditCardMax.Text);
            virtualAccount.CreditCardNum = txtCreditCardNum.Text;
            virtualAccount.CustomerName = txtBookPeople.Text;
            virtualAccount.DepositMoney = Convert.ToDecimal(txtDeposit.Text);
            virtualAccount.Customer_ID = 0;
            try
            {


                if (BLLFactory<Order>.Instance.Insert(virtualAccount))
                {

                    int num = 1;
                    foreach (OrderInfo entity in roomlist)
                    {

                        entity.BillNumber = billNumber + "_" + entity.RoomNo;
                        entity.OrderNo = billNumber + "_" + entity.RoomNo;
                        entity.CheckType = 1;
                        entity.CreateDate = Convert.ToDateTime(txtPreArrive.Text);
                        entity.PreOffDate = Convert.ToDateTime(txtPreOff.Text);
                        entity.Createor = Portal.gc.LoginInfo.FullName;
                        entity.Persons = 1;
                        entity.PreLivedDays = Convert.ToInt32(txtPrLivedDays.Text);
                        entity.PayType = txtPayType.Text;
                        entity.ProtocolUnit = cmbUnit.Text;
                        entity.TeamName = txtTeamName.Text;
                        entity.IsVirtualAccount = 0;
                        entity.IsSecret = false;
                        entity.IsPartTime = false;
                        entity.IsEachPay = false;
                        entity.Note = txtNote.Text;
                        entity.MasterRoomNo =billNumber + "-V8888";
                        entity.DiscountRate = Convert.ToDouble(entity.DiscountPrice / entity.OriginalPrice);
                        //entity.CreditCardMax = Convert.ToInt32(txtCreditCardMax.Text);
                        // entity.CreditCardNum = txtCreditCardNum.Text;
                        //entity.CustomerName = txtBookPeople.Text;
                        // entity.DepositMoney = Convert.ToDecimal(txtDeposit.Text);
                        // entity.PreGrantNum = txtPreGrantNum.Text;
                        entity.Customer_ID = 0;
                        entity.CustomerName = txtTeamName.Text + "_" + num;
                        num++;

                        BLLFactory<Order>.Instance.Insert(entity);

                    }
                    if (bookInfo != null)
                    {
                        //更新原预定订单的状态
                        BLLFactory<Book>.Instance.UpdateTeamBook(bookInfo.BookNo, 2);
                    }
                
                }
           
                MessageUtil.ShowTips("团队入住成功");
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageUtil.ShowError("团队入住出错：" + ex.Message);
            }
   
          
        }

        private void InitConsumer(int orderID, string roomType, string roomNo)
        {
            if (orderID > 0)
            {
                List<InitConsumerInfo> consumerList = BLLFactory<InitConsumer>.Instance.FindByRoomType(roomType);
                foreach (InitConsumerInfo initInfo in consumerList)
                {
                    ConsumerListInfo info = new ConsumerListInfo();
                    info.Amount = initInfo.Amount;
                    info.BeginTime = DateTime.Now;
                    info.Creator = Portal.gc.LoginInfo.FullName;
                    info.Discount = initInfo.Discount;
                    info.DiscountPrice = initInfo.DiscountPrice;
                    info.EndTime = DateTime.Now;
                    info.ItemNo = initInfo.ItemNo;
                    info.ItemName = initInfo.ItemName;
                    info.ItemType = initInfo.ItemType;
                    info.Order_ID = orderID;
                    info.Price = initInfo.Price;
                    info.Quantity = initInfo.Quantity;
                    info.RoomNo = roomNo;
                    info.Waiter = "*";

                    bool success = BLLFactory<ConsumerList>.Instance.Insert(info);
                    if (success)
                    {
                        BLLFactory<Goods>.Instance.AddStockQuantiy(info.ItemNo, info.ItemName, -Convert.ToInt32(info.Quantity));
                    }
                }
            }
        }

             

        private void btnAdd_Click(object sender, EventArgs e)
        {
            TreeNode node = this.treeView1.SelectedNode;
            if (node != null && node.Tag != null)
            {
                RoomInfo seletedRoomInfo = node.Tag as RoomInfo;
                if (seletedRoomInfo != null)
                {  
                    
                    if(!roomlist.Exists(delegate(OrderInfo r){ return r.RoomNo==seletedRoomInfo.RoomNo;}))
                    {

                        OrderInfo entity = new OrderInfo();
                        entity.RoomNo = seletedRoomInfo.RoomNo;
                        entity.RoomType = seletedRoomInfo.RoomType;
                        entity.OriginalPrice = BLLFactory<RoomType>.Instance.FindByName(seletedRoomInfo.RoomType).DayPrice;
                        entity.DiscountPrice = entity.OriginalPrice;
                        roomlist.Add(entity);
                        BindSelectedRoomInfo();

                    }

                   
                         

                }
            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {

            if (!string.IsNullOrEmpty(selectedRoomNo))
            {

                roomlist.Remove(roomlist.Find(delegate(OrderInfo r) { return r.RoomNo == selectedRoomNo; }));
                BindSelectedRoomInfo();
            
            
            }


        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            btnAdd_Click(null, null);
        }

        private void lsvAdded_DoubleClick(object sender, EventArgs e)
        {
            btnRemove_Click(null, null);
        }

        private void cmbUnit_SelectedIndexChanged(object sender, EventArgs e)
        {


           //  RefreshAddedItems();
            //this.lsvAdded.Items.Clear();
            //int i = 0;
            //foreach (string roomNo in addedRooms.Keys)
            //{
            //    ListViewItem lvItem = new ListViewItem((i + 1).ToString());
            //    lvItem.SubItems.Add(roomNo);

            //    RoomTypeInfo typeInfo = BLLFactory<RoomType>.Instance.FindByName(addedRooms[roomNo].RoomType);
            //    lvItem.SubItems.Add(typeInfo.Name);
            //    lvItem.SubItems.Add(typeInfo.DayPrice.ToString("f2"));

            //    decimal rate = 1.0M;
            //    DiscountInfoInfo mDiscountInfoInfo = BLLFactory<DiscountInfo>.Instance.FindSingle("  UnitName='" + cmbUnit.Text + "' and  RoomType ='" + addedRooms[roomNo].RoomType + "'");
            //    if (mDiscountInfoInfo != null)
            //    {


            //        lvItem.SubItems.Add((mDiscountInfoInfo.RoomDiscountPrice / mDiscountInfoInfo.RoomDiscountPrice).ToString("f2"));
            //        lvItem.SubItems.Add(mDiscountInfoInfo.RoomDiscountPrice.ToString("f2"));
            //        lvItem.Tag = addedRooms[roomNo];


            //    }
            //    else
            //    {
            //        lvItem.SubItems.Add("1.0");
            //        lvItem.SubItems.Add(typeInfo.DayPrice.ToString("f2"));
            //        lvItem.Tag = addedRooms[roomNo];


                
                
            //    }
               

            //    this.lsvAdded.Items.Add(lvItem);
            //    i++;
            //}

          
        }

        private void txtPreArrive_ValueChanged(object sender, EventArgs e)
        {
            TimeSpan span = txtPreOff.Value.Subtract(txtPreArrive.Value.Date);
            txtPrLivedDays.Text = span.Days.ToString(); 
        }

        private void txtPreOff_ValueChanged(object sender, EventArgs e)
        {
            TimeSpan span = txtPreOff.Value.Subtract(txtPreArrive.Value.Date);
            txtPrLivedDays.Text = span.Days.ToString(); 
        }

        private void txtPersons_TextChanged(object sender, EventArgs e)
        {

        }


        /// <summary>
        /// 价格编辑完毕
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgRoom_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {

            if (dgRoom.Columns[e.ColumnIndex].HeaderText == "优惠价")
            {

                try
                {
                    roomlist.Find(delegate(OrderInfo r) { return r.RoomNo == dgRoom.Rows[e.RowIndex].Cells["RoomNo"].Value.ToString(); }).DiscountPrice = Convert.ToDecimal(dgRoom.Rows[e.RowIndex].Cells["RoomDiscountPrice"].Value);

                }
                catch (Exception ex)
                {
                    dgRoom.Rows[e.RowIndex].Cells["RoomDiscountPrice"].Value = dgRoom.Rows[e.RowIndex].Cells["RoomPrice"].Value;
                    MessageUtil.ShowTips("优惠房价格式不正确");
                
                
                }
              
            
            
            }



        }

        private void dgRoom_SelectionChanged(object sender, EventArgs e)
        {

            if (dgRoom.CurrentRow != null && dgRoom.CurrentRow.Index > -1 && dgRoom.CurrentRow.Cells["RoomNo"].Value!=null)
            {
                selectedRoomNo = dgRoom.CurrentRow.Cells["RoomNo"].Value.ToString();
               
            }
        }

        private void btnSelectRoom_Click(object sender, EventArgs e)
        {

            if (booklist != null)
            {
                int roomCount = 0;
                foreach (BookInfo item in booklist)
                {

                    roomCount = item.RoomCount;
                    for (int i = 0; i < roomCount; i++)
                    {

                        List<RoomInfo> roomCanUseList  = BLLFactory<Room>.Instance.FindRoomsByCondition("  RoomType='" + item.RoomType + "'  and   (Status='" + RoomStatus.空净房.ToString() + "'  or  Status='" + RoomStatus.空脏房.ToString() + "') ");
                        foreach (RoomInfo roomItem in roomCanUseList)
                        {
                            if (roomCount > 0)
                            {


                                if (!roomlist.Exists(delegate(OrderInfo r) { return r.RoomNo == roomItem.RoomNo; }))
                                {

                                    OrderInfo entity = new OrderInfo();
                                    entity.RoomNo = roomItem.RoomNo;
                                    entity.RoomType = roomItem.RoomType;
                                    entity.OriginalPrice = BLLFactory<RoomType>.Instance.FindByName(roomItem.RoomType).DayPrice;
                                    entity.DiscountPrice = entity.OriginalPrice;
                                    roomlist.Add(entity);
                                    BindSelectedRoomInfo();

                                }
                                roomCount--;

                            }

                        }
                
                     

                    
                    
                    }


                }
            
            
            }





        }

        private void btnEditPrice_Click(object sender, EventArgs e)
        {

            if (txtHousePrice.Text.Trim() == "" ||Convert.ToInt32(txtHousePrice.Text.Trim())<1)
            {


                MessageUtil.ShowTips("请输入房价");
                return;
            
            
            }

            foreach (OrderInfo entity in roomlist)
            {

                entity.DiscountPrice = Convert.ToDecimal(txtHousePrice.Text.Trim());
                entity.DiscountRate = Convert.ToDouble(entity.DiscountPrice / entity.OriginalPrice);

            }

            BindSelectedRoomInfo();

        }

      

    }
}
